import { FormProps, FormSchema } from '@/components/Table'
import { BasicColumn } from '@/components/Table/src/types/table'
import { pattern } from '@/utils/validate/index'

import api from '@/api'
const { systemNameList } = api

// 命名空间列表
export function getDeployBasicColumns(): BasicColumn[] {
  return [
    {
      title: '项目名称',
      width: 140,
      customEllipsis: true,
      dataIndex: 'appName'
    },
    {
      title: '系统名称',
      width: 160,
      customEllipsis: true,
      dataIndex: 'systemName'
    },
    {
      title: '包名称',
      width: 160,
      customEllipsis: true,
      dataIndex: 'packageName'
    },
    {
      title: '端口号',
      align: 'right',
      width: 80,
      dataIndex: 'port'
    },
    {
      title: 'CPU 核数',
      align: 'right',
      width: 80,
      dataIndex: 'cpu'
    },
    {
      title: '内存',
      width: 80,
      dataIndex: 'memory'
    },
    {
      title: '创建时间',
      width: 140,
      dataIndex: 'createDate'
    },
    {
      title: '操作',
      width: 140,
      dataIndex: 'operate'
    }
  ]
}

export function getSearchFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 80,
    baseColProps: {
      span: 6,
      md: 8,
      xl: 8,
      xxl: 6
    },
    schemas: [
      {
        field: 'packageName',
        label: '包名称',
        component: 'Input'
      }
    ]
  }
}

export function getDeployBasicFormConfig(): Partial<FormProps> {
  return {
    showActionButtonGroup: false,
    hideRequiredMark: true,
    layout: 'vertical',
    rowProps: {
      gutter: 64
    },
    baseColProps: {
      span: 12,
      style: {
        marginBottom: '4px'
      }
    },
    schemas: [
      {
        field: 'appName',
        component: 'Input',
        label: '项目名称',
        required: true
      },
      {
        field: 'systemName',
        label: '所属系统',
        component: 'ApiSelect',
        rules: [{ required: true, trigger: 'change' }],
        componentProps: {
          api: systemNameList,
          resultField: 'result',
          labelField: 'systemName',
          valueField: 'systemName',
          immediate: true
        }
      },
      {
        field: 'packageName',
        component: 'Input',
        label: '包名称',
        required: true
      }
    ]
  }
}

export function getDeployConfigureFormConfig(): Partial<FormProps> {
  return {
    showActionButtonGroup: false,
    hideRequiredMark: true,
    layout: 'vertical',
    rowProps: {
      gutter: 64
    },
    baseColProps: {
      span: 12,
      style: {
        marginBottom: '4px'
      }
    },
    schemas: [
      {
        field: 'port',
        component: 'Input',
        label: '端口号',
        rules: [
          {
            required: true,
            message: '请输入端口号'
          },
          {
            pattern: pattern.regexp_port,
            message: '请输入正确的端口号(0-65535)'
          }
        ]
      },
      {
        field: 'cpu',
        component: 'Select',
        label: 'CPU核数',
        rules: [{ required: true, trigger: 'change' }],
        defaultValue: '1',
        componentProps: {
          options: [
            {
              label: '1核',
              value: '1',
              key: '1'
            },
            {
              label: '2核',
              value: '2',
              key: '2'
            },
            {
              label: '4核',
              value: '4',
              key: '4'
            },
            {
              label: '8核',
              value: '8',
              key: '8'
            }
          ]
        }
      },
      {
        field: 'memory',
        component: 'Select',
        label: '内存',
        rules: [{ required: true, trigger: 'change' }],
        defaultValue: '1024Mi',
        componentProps: {
          options: [
            {
              label: '1024Mi',
              value: '1024Mi',
              key: '1024Mi'
            },
            {
              label: '2048Mi',
              value: '2048Mi',
              key: '2048Mi'
            },
            {
              label: '4096Mi',
              value: '4096Mi',
              key: '4096Mi'
            },
            {
              label: '8192Mi',
              value: '8192Mi',
              key: '8192Mi'
            }
          ]
        }
      }
    ]
  }
}
